﻿using Assessment.BLL;
using Assessment.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Index_MedicalRecord_MedicalRecordList : BasePage_Index
{
    #region 属性
    private string StrWhere
    {
        get
        {
            return ViewState["StrWhere"] == null ? "" : ViewState["StrWhere"].ToString();
        }
        set
        {
            ViewState["StrWhere"] = value;
        }
    }
    #endregion

    Sys_UserBLL bll = new Sys_UserBLL();
    Sys_RoleBLL role_bll = new Sys_RoleBLL();

    #region 加载
    protected void Page_Load(object sender, EventArgs e)
    {
        //检验用户权限
        //base.CheckUserPermission("001001");

        if (!IsPostBack)
        {
            base.SetBtnGotoBackUrl("/Index/Main.aspx");

            //设置分页控件文本
            setLanguage();

            //绑定数据
            BindRepeaterData("1=1");

        }
    }

    /// <summary>
    /// 设置分页控件文本
    /// </summary>
    private void setLanguage()
    {
        TextUtility.SetPaginateCtlText(PaginateCtl);
    }
    #endregion

    #region 数据绑定
    private void BindRepeaterData(string swhere)
    {
        PaginateCtl.PageSize = 10;
        int pageIndex = PaginateCtl.CurrentPageIndex;
        int pageSize = PaginateCtl.PageSize;

        UtilityBLL ubll = new UtilityBLL();

        int rCount = 0;
        //swhere = "RoleCode<>'001' and Valid=1 and " + swhere;
        DataTable dt = ubll.GetListByPage("T_MedicalRecord", "*", "MedicalRecordId", swhere, 10, 1, 0, out rCount);

        //绑定数据源
        RepeaterList.DataSource = dt;
        //返回记录条数
        PaginateCtl.RecordCount = rCount;

        //设置记录总数的显示文本(此方法必须在设置PaginateCtl.RecordCount之后调用)
        TextUtility.SetPaginateCtlRecoText(PaginateCtl);
        RepeaterList.DataBind();
    }
    #endregion

    #region 查询
    /// <summary>
    /// 查询按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        string swhere = "1=1";
        //if (this.txt_UserName.Text.Trim().Length > 0)
        //{
        //    swhere += " and UserName like '%" + TextUtility.ReplaceText(this.txt_UserName.Text.Trim()) + "%'";
        //}
        //if (this.txt_Account.Text.Trim().Length > 0)
        //{
        //    swhere += " and Account like '%" + TextUtility.ReplaceText(this.txt_Account.Text.Trim()) + "%'";
        //}
        StrWhere = swhere;
        //分页控件回到第1页
        PaginateCtl.CurrentPageIndex = 1;
        BindRepeaterData(StrWhere);
    }
    #endregion

    #region 列表操作
    protected void RepeaterList_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        //if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        //{
        //    Label lbl_Valid = (Label)e.Item.FindControl("lbl_Valid");
        //    LinkButton lbtn_Valid = (LinkButton)e.Item.FindControl("lbtn_Valid");

        //    lbtn_Valid.Text = "修改";
        //    //设置启用禁用的显示文本
        //    if (Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "Valid")) == 0)
        //    {
        //        lbl_Valid.Text = "禁用";
        //        lbl_Valid.ForeColor = System.Drawing.Color.Red;
        //    }
        //    else
        //    {
        //        lbl_Valid.Text = "启用";
        //        lbl_Valid.ForeColor = System.Drawing.Color.Green;
        //    }
        //}
    }
    protected void RepeaterList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        //int id = int.Parse(e.CommandArgument.ToString());
        //if (e.CommandName == "Valid")
        //{
        //    try
        //    {
        //        Sys_Role model = new Sys_Role();
        //        model = bll.GetModel(id);
        //        model.Valid = model.Valid == 0 ? 1 : 0;
        //        bll.Update(model);
        //        BindRepeaterData(StrWhere);
        //    }
        //    catch (Exception ex)
        //    {
        //        base.Alert(ex.ToString());
        //    }

        //}
        //else if (e.CommandName == "Modify")
        //{
        //    Response.Redirect("UserEdit.aspx?Action=Modify&Id=" + id.ToString());
        //}
        //else if (e.CommandName == "Detail")
        //{
        //    Response.Redirect("UserEdit.aspx?Action=Detail&Id=" + id.ToString());
        //}
    }
    #endregion

    #region 分页
    /// <summary>
    /// 分页事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void PaginateCtl_PageChanged(object sender, EventArgs e)
    {
        BindRepeaterData(StrWhere);
    }
    #endregion

    #region 按钮事件
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        Response.Redirect("MedicalRecordEdit.aspx?Action=Add");
    }
    protected void btn_Edit_Click(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(this.hf_SelectedUserId.Value.Trim());
        if (id < 1)
        {
            base.Alert("请选择要操作的记录！");
            return;
        }
        Response.Redirect("MedicalRecordEdit.aspx?Action=Detail&Id=" + id);
    }
    protected void btn_Del_Click(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(this.hf_SelectedUserId.Value.Trim());
        if (id < 1)
        {
            base.Alert("请选择要操作的账号！");
            return;
        }
        bll.Delete(id);
        base.Alert("操作成功！" + id);

        this.PaginateCtl.CurrentPageIndex = 1;//分页控件还原到第1页
        BindRepeaterData("1=1");
    }
    #endregion
}